# Build recipe for icewm.
#
# Copyright (c) 2018 Markus Tornow, <tornow@riseup.net>.
# Copyright (c) 2018 Matias Fonzo, <selk@dragora.org>.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

program=icewm
version=1.4.2
release=2

# Set 'outdir' for a nice and well-organized output directory
outdir="${outdir}/${arch}/x-apps"

tarname=${program}-${version}.tar.bz2

# Remote source(s)
fetch=http://github.com/bbidulock/icewm/releases/download/${version}/$tarname

homepage=http://ice-wm.org/

description="
IceWM Window Manager.

IceWM is a window manager for the X Window System.  The goal of IceWM
is speed, simplicity, and not getting in the user's way.  It comes with
a taskbar with pager, global and per-window keybindings and a dynamic
menu system.

For more information, visit: $homepage
"

license=LGPLv2+

# Source documentation
docs="AUTHORS ChangeLog COPYING NEWS README.md THANKS TODO VERSION doc/*.html icewm.lsm"
docsdir="${docdir}/${program}-${version}"

build()
{
    set -e

    unpack "${tardir}/$tarname"

    cd "$srcdir"

    patch -Np0 -i ${worktree}/patches/icewm/fix-strlcat_strlcpy.patch
    patch -Np0 -i ${worktree}/patches/icewm/musl.patch

    # Note: IceWM has sound support for GUI events, this requires the
    # libsndfile dependency, and also has been marked as experimental;
    # we turn it to OFF by default.

    ./configure CFLAGS="$QICFLAGS" CXXFLAGS="$QICXXFLAGS" \
    LDFLAGS="$QILDFLAGS" \
     $configure_args \
     --libdir=/usr/lib${libSuffix} \
     --mandir=$mandir \
     --enable-static=no \
     --enable-shared=yes \
     --docdir=$docsdir \
     --enable-shaped-decorations \
     --enable-gradients \
     --disable-guievents \
     --disable-menus-gnome2 \
     --with-x \
     --build="$(cc -dumpmachine)"
 
    make -j${jobs} V=1
    make -j${jobs} DESTDIR="$destdir" install

    # Include xinitrc file to start ICEWM

    mkdir -p "${destdir}/etc/X11/xinit"
    cp -p "${worktree}/archive/icewm/xinitrc.icewm" "${destdir}/etc/X11/xinit/"
    chmod 644 "${destdir}/etc/X11/xinit/xinitrc.icewm"

    touch "${destdir}/etc/X11/xinit/.graft-config"

    # Compress and link man pages (if needed)
    if test -d "${destdir}/$mandir"
    then
        (
            cd "${destdir}/$mandir"
            find . -type f -exec lzip -9 '{}' +
            find . -type l | while read -r file
            do
                ln -sf "$(readlink -- "$file").lz" "${file}.lz"
                rm -- "$file"
            done
        )
    fi

    # Copy documentation
    mkdir -p "${destdir}${docsdir}"
    cp -p $docs "${destdir}${docsdir}/"
}

